﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>LayIM聊天记录 - Layui</title>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <link href="~/layui/css/pc/layim/layim.css" rel="stylesheet" />
    <link href="~/layui/css/pc/layer/layer.css" rel="stylesheet" />
    <link href="~/css/search.css" rel="stylesheet" />
    <script src="~/source/layui/layui.js"></script>
    <script>
        var content;
        layui.use(['jquery', 'laytpl','layer'], function (j, l,ly) {
            var $ = j;
            var laytpl = l;
            var layer = ly;
            var config = {
                pageindex: 1,
                pagesize: 50
            };
            var events = {
                search: function (obj) {
                    if (obj) {
                        config.pageindex = 1;
                    }
                    var keyword = $('#userKeyWord').val();
                    var val = $('input:radio[name="findtype"]:checked').val();
                    var isfile = false;
                    var isimg = false;
                    if (val == 1) { isimg = true; }
                    if (val == 2) { isfile = true;}
                    var starttime = $('#starttime').val();
                    var endtime = $('#endtime').val();

                    //
                    var container =  $('#ul_chathistory');
                    if (config.pageindex == 1) {
                        container.html('');
                    }
                    $.get('/search/history', {
                        keyword: keyword,
                        starttime: starttime,
                        endtime: endtime,
                        isfile: isfile,
                        isimg: isimg,
                        pageindex: config.pageindex,
                        pagesize: config.pagesize
                    }, function (result) {
                        if (result.data.list && result.data.list.length) {

                            var gettpl = $('#template_history').html();
                            laytpl(gettpl).render(result.data, function (html) {
                                if (config.pageindex == 1) {
                                    container.html(html);
                                } else {
                                    container.append(html);
                                }
                            });
                        }
                    });
                }
            }

            $(function () {
                events.search();
                window.search = events.search;
            });
        });

        function contentReplace(content) {
           return parent.global.content(content);
        }
    </script>
    <style>
        .layim-chat-main {
            height: 100%;
        }

        em {
            color: red;
        }

        .layui-layim-search {
            position: relative;
            top: 5px;
        }
    </style>
</head>
<body style="height:700px;">
    <div style="margin-top:10px;margin-left:5px;width:95%;height:50px;left:25px;">
        <input type="text" id="userKeyWord" style="height:30px;width:35%" title="关键字" placeholder="关键字">&nbsp;&nbsp;
        <input type="radio" name="findtype" checked="checked" value="0" />所有
        <input type="radio" name="findtype" id="radio_findpeople" value="1" />图片
        <input type="radio" name="findtype" value="2" />文件
    </div>
    <div style="margin-top:2px;margin-left:5px;width:95%;height:50px;left:25px;">
        <input type="text" id="starttime" style="height:30px;width:35%" placeholder="开始日期" />--
        <input id="endtime" type="text" style="height:30px;width:35%" placeholder="结束日期" />
        <button data-event="search" class="layui-form-button" onclick="search()">查询</button>
    </div>
    <div class="layim-chat-main">
        <ul id="ul_chathistory">
            @*<div class="layim-chat-system">
                    <span>
                        暂无历史纪录哦
                    </span>
                </div>*@
        </ul>
    </div>
</body>
</html>

<script type="text/html" id="template_history">
    {{# for(var i = 0, len = d.list.length; i < len; i++){ }}
    <li>
        <div class="layim-chat-user">
            <img src="{{ d.list[i].avatar }}">
            <cite>
                <i>
                    {{ d.list[i].addtimestr }}
                </i>
                {{ d.list[i].nickname }}
            </cite>
        </div>
        <div class="layim-chat-text">
            {{ d.list[i].isimg||d.list[i].isfile? contentReplace(d.list[i].content): d.list[i].content }}
        </div>
    </li>
    {{# } }}
</script>